package com.itheima.reggie.common;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

//结果类
@Data
public class R<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    private int code;
    private T data;
    private String msg;
    private Map map = new HashMap();

    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.code = 1;
        r.data = data;
        r.msg = "success";
        return r;
    }

    public static <T> R<T> fail(String msg) {
        R<T> r = new R<>();
        r.code = 0;
        r.msg = msg;
        return r;
    }

    public  R<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}
